import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';

import TreeItemLabel from './tree-item-label.jsx';

/**
 * 文件节点
 * @class {TreeItemFile}
 * @extends {React.Component}
 */
export default class TreeItemFile extends Component {
    static propTypes = {
        /**
         * 是否为当前焦点文件
         * @type {bool}
         */
        active: PropTypes.bool,

        /**
         * 处理打开文件
         * @type {Function}
         */
        handleOpenFile: PropTypes.func,

        /**
         * 文件路径
         * @type {string}
         */
        path: PropTypes.string,

        /**
         * 文件名
         * @type {string}
         */
        name: PropTypes.string
    };

    render() {
        const { active, handleOpenFile, path, name } = this.props;
        const className = classNames('tree-view-node file', { active });

        return (
            <li className={className}>
                <TreeItemLabel name={name}
                    isDir={false}
                    path={path}
                    onClick={() => handleOpenFile(path)} />
            </li>
        );
    }
}